package com.util;

import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.util.ByteSource;

/**
 * Created by Kak on 2020/9/2.
 */
public class MyRealmMd5 extends AuthorizingRealm{


    //授权
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {


        return null;
    }

    //认证
    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {


        //用户名
        String principal = (String)authenticationToken.getPrincipal();
        //根据用户名查询用户信息（密码）
        String hashedCredentials ="4fa51ff55b001ea9b7c55338b76834f7";
        ByteSource credentialsSalt = ByteSource.Util.bytes("kaka");
        /**
         * principal:用户信息
         * hashedCredentials：加密之后的密文
         * credentialsSalt：加密时加的盐
         * AuthorizingRealm 的派生类名称
         */
        SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(principal, hashedCredentials, credentialsSalt, getName());
        return authenticationInfo;
    }
}